package com.vanke.kotlin

import android.content.Context
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

/**
 * @name Kotlin
 * @package name：com.vanke.kotlin
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/8/2 14:48
 */
class LongPrefrence(val context: Context, val name: String,val default: Long)
    : ReadWriteProperty<Any?,Long>{

    val prefs by lazy {
        context.getSharedPreferences("default",Context.MODE_PRIVATE)
    }
    override fun getValue(thisRef: Any?, property: KProperty<*>): Long {
        return prefs.getLong(name,default)
    }

    override fun setValue(thisRef: Any?, property: KProperty<*>, value: Long) {
        prefs.edit().putLong(name,value).apply()
    }


}